/*	pit.c 
 *  Arizona State University
 *  CSE 325: Embedded Systems Programming
 *  Lab 5: Game of life
 *  Georgii Tkachuk, Brentton Garber
 *   Emails: 	gtkachuk@asu.edu btgarber@asu.edu
 * 	Description: pit module configuration. initializes two Programmable interrupt timers. 
 * 					PIT 0 is responsible for the LED matrix frame rate and the time of each turn of the game.  
 *  				PIT 1 calls reads from the nunchuk.
 * 
 */


#include "common.h"

void pit_init()
{
	//PIT 1 // LED REFRESH TIMER
	MCF_PIT0_PCSR &= ~(1); // disable timer
	
	MCF_PIT0_PCSR |= 1 << 5; // DEBUG MODE ENABLED
	MCF_PIT0_PCSR |= 1 << 4; // Immediately overwrite value in PIT counter
	MCF_PIT0_PCSR |= 1 << 3; // Enable Interrupts
	MCF_PIT0_PCSR |= 1 << 2; // Clear interrupt request flag
	MCF_PIT0_PCSR |= 1 << 1; // Make PCNTR0 value into PMR0
	
	MCF_PIT0_PMR = 4999;
	MCF_PIT0_PCSR |= (3) << 8;
	
	set_pit_handler(64+55, pit_handler);
	
	MCF_PIT0_PCSR |= 1; // Enable timer
	
	//PIT 2//GAME TIMER
	
	MCF_PIT1_PCSR &= ~(1); // disable timer
		
	MCF_PIT1_PCSR |= 1 << 5; // DEBUG MODE ENABLED
	MCF_PIT1_PCSR |= 1 << 4; // Immediately overwrite value in PIT counter
	MCF_PIT1_PCSR |= 1 << 3; // Enable Interrupts
	MCF_PIT1_PCSR |= 1 << 2; // Clear interrupt request flag
	MCF_PIT1_PCSR |= 1 << 1; // Make PCNTR0 value into PMR0
	
	MCF_PIT1_PMR = 999;
	MCF_PIT1_PCSR |= (11) << 8;
	
	set_pit_handler_1(64+56, pit_handler_1);
	
	MCF_PIT1_PCSR |= 1; // Enable timer
}

void reset_pit_1()
{
	MCF_PIT1_PMR = 999;
}

